From 958f9d921ac4a4213c9ee9f791b98121412d86e0 Mon Sep 17 00:00:00 2001 From: Boris Egorov Date: Sat, 20 Feb 2016 15:18:29 +0600 Subject: [PATCH] Avoid unnecessary rebuild on local installation Fixes #2143 --- src/cargo/ops/cargo_install.rs | 11 +++++++++-- tests/test_cargo_install.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 36fdabaf4..cf4532cb9 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -71,7 +71,11 @@ pub fn install(root: Option<&str>, let dst = root.join("bin"); try!(check_overwrites(&dst, &pkg, &opts.filter, &list)); - let target_dir = config.cwd().join("target-install"); + let target_dir = if source_id.is_path() { + config.target_dir(&pkg) + } else { + config.cwd().join("target-install") + }; config.set_target_dir(&target_dir); let compile = try!(ops::compile_pkg(&pkg, Some(source), opts).chain_error(|| { human(format!("failed to compile `{}`, intermediate artifacts can be \ @@ -89,7 +93,10 @@ pub fn install(root: Option<&str>, })); t.bins.push(dst); } - try!(fs::remove_dir_all(&target_dir)); + + if !source_id.is_path() { + try!(fs::remove_dir_all(&target_dir)); + } list.v1.entry(pkg.package_id().clone()).or_insert_with(|| { BTreeSet::new() diff --git a/tests/test_cargo_install.rs b/tests/test_cargo_install.rs index f5e42c994..db00ef614 100644 --- a/tests/test_cargo_install.rs +++ b/tests/test_cargo_install.rs @@ -2,6 +2,7 @@ use std::fmt; use std::fs::{self, File}; use std::io::prelude::*; use std::path::{Path, PathBuf}; +use support::paths::CargoPathExt; use cargo::util::ProcessBuilder; use hamcrest::{assert_that, existing_file, is_not, Matcher, MatchResult}; @@ -403,7 +404,7 @@ test!(compile_failure { error: main function not found error: aborting due to previous error failed to compile `foo v0.1.0 (file://[..])`, intermediate artifacts can be \ - found at `[..]target-install` + found at `[..]target` Caused by: Could not compile `foo`. @@ -543,3 +544,27 @@ test!(installs_from_cwd_by_default { assert_that(cargo_process("install"), execs().with_status(0)); assert_that(cargo_home(), has_installed_exe("foo")); }); + +test!(do_not_rebuilds_on_local_install { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + "#) + .file("src/main.rs", "fn main() {}"); + + assert_that(p.cargo_process("build").arg("--release"), + execs().with_status(0)); + assert_that(cargo_process("install").arg("--path").arg(p.root()), + execs().with_status(0).with_stdout("\ + Installing [..] +").with_stderr("\ +be sure to add `[..]` to your PATH to be able to run the installed binaries +")); + + assert!(p.build_dir().c_exists()); + assert!(p.release_bin("foo").c_exists()); + assert_that(cargo_home(), has_installed_exe("foo")); +}); -- 2.30.2